package com.itheima.mall.dubbo.api.pms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mall.dubbo.mapper.pms.PmsProductAttributeMapper;
import com.itheima.mall.entity.domain.pms.ProductAttribute;
import com.itheima.mall.entity.page.MyPage;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductAttributeServiceImpl extends ServiceImpl<PmsProductAttributeMapper, ProductAttribute> implements PmsProductAttributeService {
    @Autowired
    private PmsProductAttributeMapper attributeMapper;
    @Override
    public MyPage<ProductAttribute> getCategoryId(Integer cid, Integer pageNum, Integer pageSize, Integer type) {
       Page<ProductAttribute> attributePage = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<ProductAttribute> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ProductAttribute::getProductAttributeCategoryId,cid);
        lqw.eq(type != null ,ProductAttribute::getType,type);
        Page<ProductAttribute> page = attributeMapper.selectPage(attributePage, lqw);
        MyPage<ProductAttribute> myPage = MyPage.init(page);
        return myPage;
    }

    @Override
    public  List<ProductAttribute> getCategoryById(Integer productCategoryId) {
        LambdaQueryWrapper<ProductAttribute> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ProductAttribute::getProductAttributeCategoryId,productCategoryId);
        List<ProductAttribute> productAttributes = attributeMapper.selectList(lqw);
        return productAttributes;
    }

    @Override
    public List<ProductAttribute> getId(Long id) {
        LambdaQueryWrapper<ProductAttribute> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ProductAttribute::getProductAttributeCategoryId,id);
        List<ProductAttribute> attributeList = attributeMapper.selectList(lqw);
        return attributeList;
    }
}
